package com.bunkerdev.fingermania.models;

import java.io.IOException;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.View;

import com.bunkerdev.fingermania.components.Speed;
import com.bunkerdev.fingermania.utils.GIFView;
import com.bunkerdev.fingermania.utils.v;

public class Arrow extends GIFView{

	public static final int UP = 0;
	public static final int RIGHT = 1;
	public static final int DOWN = 2;
	public static final int LEFT = 3;


	private Speed speed; // the speed with its directions

	public Arrow(int position, Context context) {
		super(context);
		this.speed = new Speed();

	}


	/**
	 * Method which updates the droid's internal state every tick
	 */
	public void update() {
		int x= (int) ((speed.getXv() * speed.getxDirection())+super.getX());
		super.setX(x);
		int y= (int) ((speed.getYv() * speed.getyDirection())+super.getY());
		super.setY(y);
		
	}
	
	
	
	public Speed getSpeed() {
		return speed;
	}


	public void setSpeed(Speed speed) {
		this.speed = speed;
	}


	public Boolean isOutOfScreenLimits(int x, int y){
		Boolean res = false;
		
		// check collision with right wall if heading right
		if (getSpeed().getxDirection() == Speed.DIRECTION_RIGHT
				&& getX() > x) {
			res = true;
		}else
		// check collision with left wall if heading left
		if (getSpeed().getxDirection() == Speed.DIRECTION_LEFT
				&& testModel.getX() - testModel.getBitmap().getWidth() / 2 <= 0) {
			testModel.getSpeed().toggleXDirection();
		}
		// check collision with bottom wall if heading down
		if (testModel.getSpeed().getyDirection() == Speed.DIRECTION_DOWN
				&& testModel.getY() + testModel.getBitmap().getHeight() / 2 >= getHeight()) {
			testModel.getSpeed().toggleYDirection();
		}
		// check collision with top wall if heading up
		if (testModel.getSpeed().getyDirection() == Speed.DIRECTION_UP
				&& testModel.getY() - testModel.getBitmap().getHeight() / 2 <= 0) {
			testModel.getSpeed().toggleYDirection();
		}
		
		
		return res;
	}
	
	


}
